package flc.ast.adapter;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;

import java.io.File;

import flc.ast.utils.Content;
import flc.ast.R;
import flc.ast.bean.AppScreenBean;
import flc.ast.databinding.ItemRvAppScreenStyleBinding;
import stark.common.basic.adapter.BaseDBRVAdapter;

public class ScreenAppAdapter extends BaseDBRVAdapter<AppScreenBean, ItemRvAppScreenStyleBinding> {
    public ScreenAppAdapter() {
        super(R.layout.item_rv_app_screen_style, 0);
    }

    @Override
    protected void convert(@NonNull BaseDataBindingHolder<ItemRvAppScreenStyleBinding> holder, AppScreenBean item) {
        super.convert(holder, item);
        ItemRvAppScreenStyleBinding binding = holder.getDataBinding();
        binding.ivIcon.setImageDrawable(AppUtils.getAppIcon(item.getPackageName()));
        binding.tvTitle.setText(AppUtils.getAppName(item.getPackageName()));
        binding.tvVersion.setText(AppUtils.getAppVersionName(item.getPackageName()));
        binding.ivOrientationIcon.setImageResource(getOrientationIcon(item.getScreenOrientation()));
        binding.tvSize.setText(ConvertUtils.byte2FitMemorySize(FileUtils.getLength(AppUtils.getAppPath(item.getPackageName()))));
    }


    private int getOrientationIcon(int orientation) {
        switch (orientation) {
            case Content.UNDEFINED:
                return R.drawable.ayy1;
            case Content.PORTRAIT:
                return R.drawable.ayy2;
            case Content.REVERSE_PORTRAIT:
                return R.drawable.ayy3;
            case Content.LANDSCAPE:
                return R.drawable.ayy4;
            case Content.REVERSE_LANDSCAPE:
                return R.drawable.ayy5;
            case Content.UPSIDE_DOWN:
                return R.drawable.ayy6;
            case Content.LEFT_SIDE:
                return R.drawable.ayy7;
            case Content.RIGHT_SIDE:
                return R.drawable.ayy8;
            default:
                return 0;
        }
    }
}
